package com.example.demo.queue;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;

public class DelayQueueDemo {

    private static DelayQueue delayQueue  = new DelayQueue();
    
    public static void main(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {

                delayQueue.offer(new Task("task1", 20000));
                delayQueue.offer(new Task("task2", 10000));
                delayQueue.offer(new Task("task3", 5000));

            }
        }).start();

        while (true) {
            Delayed take = delayQueue.take();
            System.out.println(take);
        }
    }
}
